﻿using Iworld.Client.Framework.AuthorService;
using Iworld.ViewModel;
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Iworld.Client.Framework
{
    /// <summary>
    /// 注册视图模型
    /// </summary>
    public class RegisterViewModel : ViewModelBase
    {
        string _account = "";
        string _password = "";
        string _passwordCheck = "";
        string _username = "";
        string _qq="";
        string _twoLevelPassword="";
        string _twoLevelPasswordCheck= "";
        string _phone = "";
        string _identityCard = "";
        public RegisterViewModel() 
        {
            RegisterCommand = new UniversalCommand(Register);
            BackCommand = new UniversalCommand(Back);
        }

        void Register(object obj)
        {


            AuthorServiceClient asc = new AuthorServiceClient();
            asc.RegisterCompleted += asc_RegisterCompleted;
            asc.RegisterAsync(new RegisterImport() { 
             Account = this.Account, Password=this.Password, IdentityCard=this.IdentityCard
             , Phone=this.Phone, QQ=this.QQ, TwoLevelPassword=this.TwoLevelPassword, Username=this.Username
            });
        }

        void asc_RegisterCompleted(object sender, RegisterCompletedEventArgs e)
        {
            if (e.Result.Success)
            {
                Error = "注册成功!";
            }
            else
            {
                Error = e.Result.Error;
            }
        }

        

        void Back(object obj)
        {
            //ViewModelService.JumpTo(Page.登录);
            ClientViewModelService.Current.JumpTo(Page.登录);
        }

    

        /// <summary>
        /// 注册的命令
        /// </summary>
        public UniversalCommand RegisterCommand { get; set; }

        /// <summary>
        /// 返回的命令
        /// </summary>
        public UniversalCommand BackCommand { get; set; }

        /// <summary>
        /// 账号
        /// </summary>
        public string Account
        {
            get
            {
                return _account;
            }
            set
            {
                if (_account != value)
                {
                    _account = value;
                    OnPropertyChanged("Account");
                }
            }
        }

        /// <summary>
        /// 密码
        /// </summary>
        public string Password
        {
            get
            {
                return _password;
            }
            set
            {
                if (_password != value)
                {
                    _password = value;
                    OnPropertyChanged("Password");
                }
            }
        }

        public string PasswordCheck
        {
            get
            {
                return _passwordCheck;
            }
            set
            {
                if (_passwordCheck != value)
                {
                    _passwordCheck = value;
                    OnPropertyChanged("PasswordCheck");
                }
            }
        }

        /// <summary>
        /// 用户名
        /// </summary>
        public string Username
        {
            get
            {
                return _username;
            }
            set
            {
                if (_username != value)
                {
                    _username = value;
                    OnPropertyChanged("Username");
                }
            }
        }

        /// <summary>
        /// 二级密码
        /// </summary>
        public string TwoLevelPassword
        {
            get
            {
                return _twoLevelPassword;
            }
            set
            {
                if (_twoLevelPassword!= value)
                {
                    _twoLevelPassword = value;
                    OnPropertyChanged("TwoLevelPassword");
                }
            }
        }

        public string TwoLevelPasswordCheck
        {
            get
            {
                return _twoLevelPasswordCheck;
            }
            set
            {
                if (_twoLevelPasswordCheck != value)
                {
                    _twoLevelPasswordCheck = value;
                    OnPropertyChanged("TwoLevelPasswordCheck");
                }
            }
        }


        /// <summary>
        /// QQ号码
        /// </summary>
        public string QQ
        {
            get
            {
                return _qq;
            }
            set
            {
                if (_qq != value)
                {
                    _qq = value;
                    OnPropertyChanged("QQ");
                }
            }
        }

        /// <summary>
        /// 电话号码
        /// </summary>
        public string Phone
        {
            get
            {
                return _phone;
            }
            set
            {
                if (_phone != value)
                {
                    _phone = value;
                    OnPropertyChanged("Phone");
                }
            }
        }

        /// <summary>
        /// 身份证
        /// </summary>
        public string IdentityCard
        {
            get
            {
                return _identityCard;
            }
            set
            {
                if (_identityCard != value)
                {
                    _identityCard = value;
                    OnPropertyChanged("IdentityCard");
                }
            }
        }



    }
}
